/* ***********************************************************************************************
		"The Value of Urgency: Evidence from Congestion Pricing Experiments"
		Antonio M. Bento, Kevin Roth, Andrew R. Waxman
		Code: Andrew Waxman - awaxman@utexas.edu
		Last Updated: 04/04/24 			
*********************************************************************************************** 
doAll.do - master do-file for all results.

TO REPLICATE RESULTS: Change global path on line 20 to directory of replication files on local machine
************************************************************************************************/


***********************************************************************************************
*										Preliminaries
***********************************************************************************************
set scheme s1mono
graph set window fontface "Times New Roman"
/*			| SET PATH ON LOCAL MACHINE HERE & UNCOMMENT	|
  			V                                				V  */
* global $path "[YOUR PATHNAME HERE]"  			
						
cd "$path"

***********************************************************************************************
*										0. Install Dependencies and Create Directories
***********************************************************************************************

do .\programs\00_setup.do 											// Create folder structure
do .\programs\0_setup.do 										// download/install dependencies


***********************************************************************************************
*										1. Clean raw data
***********************************************************************************************
do .\programs\1_cleaning\cleanrawdata.do 					// Clean raw ExpressLanes transponder data
do .\programs\1_cleaning\makeZIP_accts.do 					// Clean Account-level Data
do .\programs\1_cleaning\cleancensus.do 					// Merge Census data
do .\programs\1_cleaning\preparemergedtransppemsuncollapsed.do // Clean PeMS data
do .\programs\1_cleaning\meanpastspeeds.do 					// Moments of Speed Distribution
do .\programs\1_cleaning\MLreliability.do 					// Construct Mainline Reliability
do .\programs\1_cleaning\HVreliability.do 					// Construct ExpressLanes Reliability
do .\programs\1_cleaning\laneuseanalysis.do 				// Merge PeMS and ExpressLanes data
do .\programs\1_cleaning\make_msrp_data.do 					// Merge Vehicle Values to Transponder data
do .\programs\1_cleaning\genIVs_v2.do 						// Construct lags and leads of dTT for IV

***********************************************************************************************
*										2. Produce Figures & Tables from Text
***********************************************************************************************
// Main Text Figures
do .\programs\2_analysis\makeFigure2.do 					// WILLINGNESS-TO-PAY PER HOUR AND DEMAND FOR TRIPS IN THE EXPRESSLANES 
do .\programs\2_analysis\makeFigure3.do 					// I-10 W EXPRESSLANES TRIP DENSITY DURING AM PEAK
texdoc do .\programs\2_analysis\makeFigure4.do				// CONCEPTUAL BASIS FOR THE VALUE OF URGENCY
cd "$path\results\maintablesfigs\figs\"
shell pdflatex  Figure4.tex
shell convert -density 300 Figure3.pdf -quality 90 Figure4.png // this requires ImageMagick to be installed - https://imagemagick.org/script/download.php
cd "$path"
putexcel set ".\results\maintablesfigs\maintextFigsTabs.xlsx", sheet("Figure 4") modify
putexcel A1 = picture(.\results\maintablesfigs\figs\Figure4-0.png)
putexcel AA1 = picture(.\results\maintablesfigs\figs\Figure4-1.png)

do .\programs\2_analysis\makeFigure5pa.do 					// ESTIMATES OF THE VALUE OF URGENCY OVER THE AM PEAK
do .\programs\2_analysis\makeFigure5pb.do 					// TOLL PER MILE BY HOUR & MONTH
do .\programs\2_analysis\makeFigure5pc.do 					// DEPARTURE AND ARRIVAL TIMES FOR WORK, LA COUNTY, ACS
do .\programs\2_analysis\makeFigure5pd.do 					// AVERAGE HOURLY WAGE BY ARRIVAL TIME TO WORK LA COUNTY, ACS
do .\programs\2_analysis\makeFigure6.do 					// ESTIMATED DISTRIBUTION OF VALUE OF TIME AND URGENCY
do .\programs\2_analysis\makeFigure7.do 					// MODEL PREDICTED WTP FROM ALTERNATIVE FUNCTIONAL FORMS

// Main Text Tables
do .\programs\2_analysis\makeTable1.do 						// Trip-Level Summary Statistics by Decile of Travel Time Savings
do .\programs\2_analysis\makeTable2.do 						// Account Level Regressions I-10 West
do .\programs\2_analysis\makeTable2_coeftest.do 			// Calculate whether coef in cols 1-2 diff from III
do .\programs\2_analysis\makeTable2_coeftest.do 			// Calculate whether coef in cols 1-2 diff from III
do .\programs\2_analysis\makeTable3.do 						// Homogeneous Hedonic Price Function Estimates: Fixed Effects Models
do .\programs\2_analysis\makeTable4.do 						// Account Level Regressions I-10 West: Weekend Control Group
do .\programs\2_analysis\makeTable5_pa_colsI_II.do 			// Hedonic Price Function Estimates: Robustness Checks (Panel A,columns I-II)
do .\programs\2_analysis\makeTable5_pa_colsIII_V.do 		// Hedonic Price Function Estimates: Robustness Checks (Panel A,columns III-V)
do .\programs\2_analysis\makeTable5_pb.do 					// Hedonic Price Function Estimates: Robustness Checks (Panel B)
do .\programs\2_analysis\makeTable5_pc.do 					// Hedonic Price Function Estimates: Robustness Checks (Panel C)
*********************************************************************************************** 
* 										3. Produce Appendix Figures & Tables
************************************************************************************************/

// Appendix Figures
* insert  App Fig 2 										// I-10W ExpressLanes Design
putexcel set ".\results\appendix\AppendixFigsTabs.xlsx", sheet("Appendix Figure B.1") modify
putexcel A1 = picture(.\data\raw\ELMap.tif)

do .\programs\2_analysis\appendix\makeAppFig3.do 			// Variation in Time Savings and Reliability			
do .\programs\2_analysis\appendix\makeAppFig4.do 			// VARIATION IN MAINLINE SPEED DISTRIBUTION BY HOUR AND DAY-OF-WEEK
do .\programs\2_analysis\appendix\makeAppFig5.do 			// AVERAGE WILLINGNESS-TO-PAY PER HOUR OF TRIPS IN THE EXPRESSLANES BY MONTHLY AM PEAK TRIP FREQUENCY
do .\programs\2_analysis\appendix\makeAppFig6.do 			// AVERAGE WILLINGNESS-TO-PAY PER HOUR OF TRIPS IN THE EXPRESSLANES BY NUMBER OF PREVIOUS AM PEAK EXPRESSLANES APPEARANCES
do .\programs\2_analysis\appendix\makeAppFig7.do 			// AVERAGE TIME SAVED OVER AM PEAK BY MONTH OF PROGRAM



// Appendix Tables
do .\programs\2_analysis\appendix\makeAppTab1.do 			// ENTRY-EXIT FREQUENCY MATRIX
do .\programs\2_analysis\appendix\makeAppTab2.do 			// RDD: EXPRESSLANES OPENING EFFECT DURING AM
do .\programs\2_analysis\appendix\makeAppTab3.do 			// TRIP- & INDIVIDUAL-LEVEL WILLINGNESS-TO-PAY ESTIMATES BY DECILE OF TRAVEL TIME SAVINGS
do .\programs\2_analysis\appendix\makeAppTab4.do 			// Monthly Frequency by Travel Time Savings Decile
do .\programs\2_analysis\appendix\makeAppTab5.do 			// MOST COMMON VEHICLES BY DECILE OF TRAVEL TIME SAVINGS
do .\programs\2_analysis\appendix\makeAppTab6.do 			// REGRESSION OF DISTANCE ON EXIT TIME
do .\programs\2_analysis\appendix\makeAppTab7.do 			// HOMOGENEOUS AGENT HEDONIC PRICE FUNCTION ESTIMATES: STANDARD ERROR CLUSTERING
do .\programs\2_analysis\appendix\makeAppTab8.do 			// HOMOGENEOUS AGENT HEDONIC PRICE FUNCTION ESTIMATES: STANDARD ERROR ROBUSTNESS
do .\programs\2_analysis\appendix\makeAppTab9.do 			// HOMOGENEOUS AGENT HEDONIC PRICE FUNCTION ESTIMATES: MODEL WITHOUT RELIABILITY
do .\programs\2_analysis\appendix\makeAppTab10.do 			// HOMOGENEOUS AGENT HEDONIC PRICE FUNCTION ESTIMATES:INCLUDING NEGATIVE TRAVEL TIME DIFFERENCE & NEGATIVE RELIABILITY
do .\programs\2_analysis\appendix\makeAppTab11.do 			// HOMOGENEOUS AGENT HEDONIC PRICE FUNCTION ESTIMATES: RELIABILITY MOMENTS AND WINDOW ROBUSTNESS
do .\programs\2_analysis\appendix\makeAppTab12.do 			// HEDONIC PRICE FUNCTION ESTIMATES: TWO-STAGE LEAST SQUARES FIRST-STAGE
do .\programs\2_analysis\appendix\makeAppTab13.do 			// HOMOGENEOUS AGENT HEDONIC PRICE FUNCTION ESTIMATES: TWO-STAGE LEAST SQUARES SECOND-STAGE
do .\programs\2_analysis\appendix\makeAppTab14.do 			// REGRESSION OF INDIVIDUAL-LEVEL ESTIMATES ON VEHICLE PRICES
do .\programs\2_analysis\appendix\makeAppTab15.do 			// HOMOGENEOUS AGENT HEDONIC PRICE FUNCTION ESTIMATES: OTHER CORRIDORS
do .\programs\2_analysis\appendix\makeAppTab16.do 			// HOMOGENEOUS AGENT HEDONIC PRICE FUNCTION ESTIMATES: SEGMENT HETEROGENEITY
do .\programs\2_analysis\appendix\makeAppTab17.do 			// HOMOGENEOUS AGENT HEDONIC PRICE FUNCTION ESTIMATES: OTHER FUNCTIONAL FORM
do .\programs\2_analysis\appendix\makeAppTab18.do 			// HOMOGENEOUS AGENT HEDONIC PRICE FUNCTION ESTIMATES: MODELS WITHOUT A CONSTANT
do .\programs\2_analysis\appendix\makeAppTab19.do 			// HOMOGENEOUS AGENT HEDONIC PRICE FUNCTION ESTIMATES: EXPECTED VS. REALIZED TRAVEL TIMES
do .\programs\2_analysis\appendix\makeAppTab20.do 			// HOMOGENEOUS AGENT HEDONIC PRICE FUNCTION ESTIMATES: I-210W AS A SUBSTITUTE ROUTE
do .\programs\2_analysis\appendix\makeAppTab21.do 			// HOMOGENEOUS AGENT HEDONIC PRICE FUNCTION ESTIMATES: RESTRICTED TIME WINDOWS
do .\programs\2_analysis\appendix\makeAppTab22.do 			// HOMOGENEOUS AGENT HEDONIC PRICE FUNCTION ESTIMATES: GAS PRICE AND WEATHER ROBUSTNESS
